import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_share/flutter_share.dart';
import 'package:flutterdemo/0demo/route/fade_route.dart';
import 'package:flutterdemo/0demo/ui/AnimatedListTestPage.dart';
import 'package:flutterdemo/0demo/ui/gesture/photo_view/my_photo_view.dart';
import 'package:flutterdemo/0demo/ui/overlay_manager/overlay_queue_test_page.dart';
import 'package:flutterdemo/0demo/ui/popup_route/popup_route_test.dart';
import 'package:flutterdemo/0demo/ui/text/overflow_text.dart';
import 'package:flutterdemo/0demo/ui/text/test_text_expand.dart';
import 'package:flutterdemo/0demo/ui/vertical_page_view/vertical_page_view.dart';

import 'animated_wrapper/animated_wrapper2/animated_wrapper_page2.dart';
import 'animated_wrapper/animated_wrapper1/animated_wrapper_page1.dart';
import 'discount_bg.dart';
import 'overlay_manager/overlay_manager.dart';
import 'test_keyboard_page.dart';

class UIPage extends StatefulWidget {
  @override
  _UIPageState createState() => _UIPageState();
}

class _UIPageState extends State<UIPage> {
  String _word = "";

  TextEditingController _inputController;

  @override
  void initState() {
    _inputController = TextEditingController.fromValue(TextEditingValue(
        // 设置内容
        text: _word,
        // 保持光标在最后， 貌似无用
        selection: TextSelection.fromPosition(
            TextPosition(affinity: TextAffinity.downstream, offset: _word.length))));

    // 坑：onChange方法无法监听到_inputController改变的值，所以用controller监听最好
    _inputController.addListener(() {
      print("_inputController.text == ${_inputController.text}");
      _word = _inputController.text;
      setState(() {});
    });

    overlayManager.addListenShowOrDismiss(_overlayListener);
    super.initState();
  }

  void _overlayListener(bool showOrDismiss, int overlayId) {
    print("show: $showOrDismiss, overlayId = $overlayId");
  }

  @override
  void dispose() {
    overlayManager.removeListenShowOrDismiss(_overlayListener);
    super.dispose();
  }

  IconData _actionIcon = Icons.delete;

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1080, height: 1920, allowFontScaling: false);

    return Scaffold(
      backgroundColor: Colors.blueGrey,
      appBar: AppBar(
        title: Text("ui"),
        actions: <Widget>[
          AnimatedSwitcher(
            transitionBuilder: (child, anim) {
              return ScaleTransition(child: child, scale: anim);
            },
            duration: Duration(milliseconds: 300),
            child: IconButton(
                key: ValueKey(_actionIcon),
                icon: Icon(_actionIcon),
                onPressed: () {
                  setState(() {
                    if (_actionIcon == Icons.delete)
                      _actionIcon = Icons.done;
                    else
                      _actionIcon = Icons.delete;
                  });
                }),
          )
        ],
      ),
      body: CustomScrollView(
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: SizedBox(height: 20.h),
          ),
          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              child: Text("overlay"),
              onPressed: () {
                if (overlayManager.isShow) {
                  overlayManager.dismiss();
                } else {
                  int id = overlayManager.show(
                    Align(
                      alignment: Alignment.bottomCenter,
                      child:
                          Container(height: 200, width: 200, color: Colors.blue.withOpacity(0.4)),
                    ),
                    context,
                  );
                  print("overlayId == $id");
                }
              },
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: ElevatedButton(
              child: Text("overlay queue test"),
              onPressed: () {
                Navigator.push(context, FadeRoute(page: OverlayQueueTestPage()));
              },
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: ElevatedButton(
              child: Text("popup route"),
              onPressed: () {
                Navigator.push(context, FadeRoute(page: PopupPage()));
              },
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverPersistentHeader(
            delegate: MySliverPersistentHeaderDelegate(),
            pinned: false,
            floating: false,
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverPersistentHeader(
            delegate: MySliverPersistentHeaderDelegate(),
            pinned: true,
            floating: true,
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: Container(
              height: 200.h,
              margin: EdgeInsets.only(left: 30.w, right: 30.w),
              child: TextField(
                key: Key("input_code"),
                onChanged: (value) {
                  _onTextChanged(value);
                },
                keyboardType: TextInputType.number,
                maxLength: 4,
                controller: _inputController,
                style: TextStyle(fontSize: 49.sp, color: Colors.blue),
                decoration: InputDecoration(
                  hintText: '请输入激活码',
                  counterText: "aa",
                  suffixIcon: Icon(
                    Icons.star,
                    color: Colors.redAccent,
                  ),
                  prefixIcon: Icon(Icons.star),
                  hintStyle: TextStyle(color: Color(0xff9e51ff)),
                  contentPadding: EdgeInsets.only(left: 10, top: ScreenUtil().setHeight(10)),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(5.0),
                    borderSide: BorderSide(
                      color: Color(0xff9e51ff),
                    ), //这个不生效
                  ),
                  enabledBorder: OutlineInputBorder(
                    //未选中时候的颜色
                    borderRadius: BorderRadius.circular(5.0),
                    borderSide: BorderSide(
                      color: Color(0xff9e51ff),
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    //选中时外边框颜色
                    borderRadius: BorderRadius.circular(5.0),
                    borderSide: BorderSide(
                      color: Color(0xff9e51ff),
                    ),
                  ),
//                focusedBorder: UnderlineInputBorder(
//                  //选中时下边框颜色
//                  borderSide: BorderSide(color: Colors.red),
//                ),
                ),
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: ElevatedButton(
              key: Key("activeButton"),
              onPressed: () {
                setState(() {
                  _word = _inputController.text;
                });
              },
              child: Text("active"),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: Text(_word),
          ),

          SliverToBoxAdapter(
            child: SizedBox(height: 20),
          ),

          SliverToBoxAdapter(
            child: Column(
              children: <Widget>[
                SizedBox(
                  height: 10.h,
                ),
                TextButton(
                  onPressed: () {
                    _inputController.text = "11";
                    _word = _inputController.text;
                    setState(() {});
                  },
                  child: Text("用inputController改变text测试onChange监听"),
                )
              ],
            ),
          ),
          // IndexStack
          SliverToBoxAdapter(
            child: IndexedStack(
              index: 1,
              children: <Widget>[
                Container(
                  height: 200.h,
                  width: 200.w,
                  color: Colors.blue,
                ),
                Container(
                  height: 100.h,
                  width: 100.w,
                  color: Colors.redAccent,
                )
              ],
            ),
          ),

          SliverToBoxAdapter(
            child: Column(
              children: <Widget>[
                SizedBox(
                  height: 20.h,
                ),
                Text(".9图片"),
                SizedBox(
                  height: 20.h,
                ),
              ],
            ),
          ),

          SliverToBoxAdapter(
            child: Container(
              padding: EdgeInsets.all(20.w),
              child: Stack(
                children: <Widget>[
                  Container(
                      margin: EdgeInsets.fromLTRB(40, 0, 0, 0),
                      child: Image.asset(
                        'assets/images/bubble_arrow.png',
                        width: 30,
                        height: 18,
                      )),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        centerSlice: Rect.fromLTWH(19, 13, 8, 8),
                        image: AssetImage(
                          'assets/images/message_bubble.png',
                        ),
                      ),
                    ),
                    constraints: BoxConstraints(
                      minWidth: 48,
                      maxWidth: 480,
                    ),
                    //调整文字的位置，要不然会跟image并排
                    padding: EdgeInsets.fromLTRB(18.5, 3.0, 14.5, 20.0),
                    child: Text(
                      '点XXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX',
                      style: TextStyle(color: Colors.red, fontSize: 15.0),
                    ),
                  ),
                ],
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 20.h,
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              alignment: Alignment.bottomRight,
              decoration: BoxDecoration(
                image: DecorationImage(
                  fit: BoxFit.fill,
                  centerSlice: Rect.fromLTRB(35, 91, 107, 114),
                  image: AssetImage(
                    'assets/images/bg_chat_message_send.png',
                  ),
                ),
              ),
              constraints: BoxConstraints(
                minWidth: 48.w,
                maxWidth: 280.w,
              ),
              //调整文字的位置，要不然会跟image并排
              padding: EdgeInsets.fromLTRB(18.5, 3.0, 14.5, 20.0),
              child: Text(
                '111\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX111\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX111\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX\nXXXXXXXXX',
                style: TextStyle(color: Colors.red, fontSize: 15.0),
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: TextButton(
              onPressed: _showLoadingDialog,
              child: Text("显示loading dialog"),
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () {
                Navigator.push(context, CupertinoPageRoute(builder: (context) => TestTextExpand()));
              },
              child: Text("expand text listen line number."),
            ),
          ),
          SliverToBoxAdapter(child: SizedBox(height: 10)),
          // text无法解决，需要自己手动根据文本信息设置替换\n
          SliverToBoxAdapter(
              child: Container(
                  width: 200,
                  child: Text(
                      "text换行overflow无效问题，后面折行不显示overflow"
                      "\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                      maxLines: 1,
                      softWrap: true,
                      overflow: TextOverflow.ellipsis))),
          SliverToBoxAdapter(
              child: Container(
                  width: 200,
                  child: OverflowText(
                    "text换行overflow无效问题，后面折行不显示overflow"
                    "\naaa"
                    ""
                    "\naaaaaaa"
                    ""
                    "\naa"
                    ""
                    "\naa"
                    "\naaaa"
                    "\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                    maxLines: 7,
                    style: TextStyle(color: Colors.red),
                  ))),
          SliverToBoxAdapter(
              child: Container(
                  width: 40,
                  child: OverflowText(
                    "豫章故郡，洪都新府。\n星分翼轸，地接衡庐。襟三江而带五湖，控蛮荆而引瓯越,豫章故郡，\n洪都新府。星分翼轸，地接衡庐。襟三江而带五湖，控蛮荆而引瓯越,"
                    "豫章故郡，洪都新府。星分翼轸，\n地接衡庐。襟三江而带五湖，控蛮荆而引瓯越",
                    maxLines: 1,
                    style: TextStyle(color: Colors.red),
                  ))),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: _showModal,
              child: Text("底部非半屏模态框"),
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: _animatedList,
              child: Text("AnimatedList"),
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () {
                Navigator.push(
                    context, CupertinoPageRoute(builder: (context) => TestKeyboardPage()));
              },
              child: Text("test keyboard focus"),
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () async {
                // Share.share("https://m.house730.com/house-map?fromapp=android&id=1913365&name=將軍澳中心&lat=22.307087&lng=114.257106");
                await FlutterShare.share(
                    title: "title",
                    text:
                        "https://m.house730.com/house-map?fromapp=android&id=1913365&name=將軍澳中心&lat=22.307087&lng=114.257106",
                    linkUrl:
                        "https://m.house730.com/house-map?fromapp=android&id=1913365&name=將軍澳中心&lat=22.307087&lng=114"
                        ".257106",
                    chooserTitle: "chooserTitle"
                    // linkUrl: url,
                    );
              },
              child: Text("share"),
            ),
          ),
          SliverToBoxAdapter(
            child: Column(
              children: [
                Text("流式布局"),
                Container(
                  width: ScreenUtil.screenWidth,
                  color: Colors.grey,
                  child: Wrap(
                    spacing: 8, // 主轴(水平)方向间距
                    runSpacing: 0, // 纵轴（垂直）方向间距
                    alignment: WrapAlignment.start, //沿主轴方向居左
                    children: <Widget>[
                      Chip(
                        avatar: CircleAvatar(backgroundColor: Colors.blue, child: Text('A')),
                        label: Text('Hamilton1111'),
                      ),
                      Chip(
                        avatar: CircleAvatar(backgroundColor: Colors.blue, child: Text('M')),
                        label: Text('sadasd'),
                      ),
                      Chip(
                        avatar: CircleAvatar(backgroundColor: Colors.blue, child: Text('H')),
                        label: Text('哈哈哈'),
                      ),
                      Chip(
                        avatar: CircleAvatar(backgroundColor: Colors.blue, child: Text('J')),
                        label: Text('1'),
                      ),
                      Text("aaaa"),
                      Text("sadsadsadsas"),
                      Text("sadsad"),
                      Text("aaaa"),
                      Text("sadsadsad"),
                      Text("aaaa"),
                      Text("sadsadsa"),
                      Text("aaaa"),
                      Text("asadsadsadaaa"),
                      Text("aaaa"),

                      // 不可设置alignment属性，否则会填充父容器。
                      Container(
                        child: Text("aaaa"),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          border: Border(
                            top: BorderSide(
                              width: 1.0,
                              color: Color(0xffaaaaaa),
                            ),
                            bottom: BorderSide(
                              width: 1.0,
                              color: Color(0xffaaaaaa),
                            ),
                            left: BorderSide(
                              width: 1.0,
                              color: Color(0xffaaaaaa),
                            ),
                            right: BorderSide(
                              width: 1.0,
                              color: Color(0xffaaaaaa),
                            ),
                          ),
                        ),
                      ),
                      Container(
                        child: Text("aaaa"),
                        padding: EdgeInsets.all(5),
                        decoration: BoxDecoration(
                            border: Border.all(
                                color: Color.fromARGB(255, 51, 51, 51),
                                width: 3.h,
                                style: BorderStyle.solid)),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
            child: Padding(
              padding: EdgeInsets.all(10),
              child: Row(
                children: [
                  Icon(Icons.add),
                  Spacer(),
                  Icon(Icons.add),
                ],
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
            child: Container(
              height: 40,
              child: Padding(
                padding: EdgeInsets.all(10),
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Container(
                      color: Colors.red,
                      width: 10,
                    ),
                    // 这里可以看到，设置的宽度有效，按实际宽度来的，这是和expanded的区别
                    Flexible(
                      flex: 1,
                      child: Container(
                        width: 120,
                        color: Colors.blue,
                      ),
                    ),
                    Container(
                      width: 20,
                      color: Colors.yellow,
                    ),
                  ],
                ),
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
            child: Container(
              width: double.infinity,
              height: 40,
              child: Padding(
                padding: EdgeInsets.all(10),
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Expanded(
                      child: Container(
                        height: 10,
                        color: Colors.red,
                      ),
                    ),
                    // 这里可以看到，设置的宽度无效，还是填充
                    Expanded(
                      flex: 2,
                      child: Container(
                        width: 120,
                        color: Colors.blue,
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Container(
                        color: Colors.yellow,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () {
                _exitApp(context);
              },
              child: Text("exit app"),
            ),
          ),
          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),
          SliverToBoxAdapter(
            child: ElevatedButton(
              onPressed: () {
                Navigator.push(context, CupertinoPageRoute(builder: (context) => MyPhotoView()));
              },
              child: Text("my photo view"),
            ),
          ),
          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverFillRemaining(
            hasScrollBody: false,
            child: Container(
              color: Colors.blue[100],
              child: Icon(
                Icons.sentiment_very_satisfied,
                size: 75,
                color: Colors.blue[900],
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          // app bar渐变参考：https://blog.csdn.net/guiying712/article/details/104445456
          // 纯色渐变背景
          SliverToBoxAdapter(
            child: ClipPath(
              clipper: PromptClipper(),
              child: Container(
                height: 250,
                width: MediaQuery.of(context).size.width,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [
                      Colors.pinkAccent,
                      Colors.white,
                    ],
                  ),
                ),
              ),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
            child: Container(
              child: DiscountBg("30% off !!!!"),
              margin: EdgeInsets.only(left: 20),
            ),
          ),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
              child: ElevatedButton(
            onPressed: () {
              Navigator.push(context, CupertinoPageRoute(builder: (context) => VerticalPageView()));
            },
            child: Text("vertical page view"),
          )),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
              child: ElevatedButton(
            onPressed: () {
              Navigator.push(
                  context, CupertinoPageRoute(builder: (context) => AnimatedWrapperPage1()));
            },
            child: Text("animated wrapper1"),
          )),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),

          SliverToBoxAdapter(
              child: ElevatedButton(
            onPressed: () {
              Navigator.push(
                  context, CupertinoPageRoute(builder: (context) => AnimatedWrapperPage2()));
            },
            child: Text("animated wrapper2"),
          )),

          SliverToBoxAdapter(
            child: SizedBox(
              height: 50.h,
            ),
          ),
        ],
      ),
    );
  }

  void _onTextChanged(String value) {
    _word = value;
    setState(() {});
  }

  void _showLoadingDialog() {
    showDialog(
      context: context,
      barrierDismissible: false, //点击遮罩不关闭对话框
      builder: (context) {
        return UnconstrainedBox(
          constrainedAxis: Axis.vertical,
          child: SizedBox(
            width: 800.w,
            child: AlertDialog(
              content: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  CircularProgressIndicator(),
//                  Padding(
//                    padding: const EdgeInsets.only(top: 26.0),
//                    child: Text("正在加载，请稍后..."),
//                  )
                ],
              ),
            ),
          ),
        );
      },
    );
  }

  void _showModal() {
    showModalBottomSheet(
      context: context,
      //一：设为true，此时为全屏展示
      isScrollControlled: true,
      builder: (BuildContext context) {
        return Container(
          color: Colors.red,
          height: 500.w,
          child: Column(
            children: <Widget>[
              Container(
                height: 200.w,
                color: Colors.grey,
                margin: EdgeInsets.only(left: 60.w, right: 60.w, top: 30.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    TextButton(
                      child: Column(
                        children: <Widget>[
                          SizedBox(height: 10.w),
                          Image.asset(
                            "assets/images/ic_nav_news_actived.png",
                            width: 80.w,
                            height: 80.w,
                          ),
                          SizedBox(height: 10.w),
                          Text("软件商店"),
                        ],
                      ),
                      onPressed: () => "",
                    ),
                    TextButton(
                      child: Column(
                        children: <Widget>[
                          SizedBox(height: 10.w),
                          Image.asset(
                            "assets/images/ic_nav_news_normal.png",
                            width: 80.w,
                            height: 80.w,
                          ),
                          SizedBox(height: 10.w),
                          Text("UC浏览器"),
                        ],
                      ),
                      onPressed: () => "",
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: 20.w,
              ),
              Divider(
                height: 1.h,
                color: Colors.black,
                indent: 60.w,
                endIndent: 60.w,
              ),
              Container(
                child: ListTile(
                  title: Text('取消', style: TextStyle(fontSize: 45.sp), textAlign: TextAlign.center),
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  void _animatedList() {
    Navigator.push(context, CupertinoPageRoute(builder: (context) => AnimatedListTest()));
  }

  // 仅对Android有效，IOS需要exit(0)
  void _exitApp(BuildContext context) {
    if (Platform.isAndroid) {
      // 该方法仅对Android有效
      SystemNavigator.pop();
    } else {
      // 白屏
      Navigator.of(context).popUntil(ModalRoute.withName("/"));
      Navigator.maybeOf(context)?.pop();

      // IOS只能exit(0)，或者需要原生支持
    }
  }
}

class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
        color: Colors.blue,
        alignment: Alignment.center,
        child: Text('我是一个SliverPersistentHeader', style: TextStyle(color: Colors.white)));
  }

  @override
  double get maxExtent => 200.0;

  @override
  double get minExtent => 100.0;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false; // 如果内容需要更新，设置为true
}

class PromptClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    const double triangleW = 10;
    var path = Path();
    path.lineTo(triangleW, size.height);
    path.lineTo(size.width - triangleW, size.height);
    path.lineTo(size.width, 0);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return false;
  }
}
